package com.yida.gwj.expend.enums;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;

/**
 * 业务步骤转换枚举
 *
 * @author liangp
 * @date 2023/03/23
 */
public enum BusinessStepTranslateEnum {
    /**
     *
     */
    OUTSIDE("00", "外网"),
    INNER("01", "内网");

    private final String code;
    private final String info;

    BusinessStepTranslateEnum(String code, String info) {
        this.code = code;
        this.info = info;
    }

    public String getCode() {
        return code;
    }

    public String getInfo() {
        return info;
    }

    public static Long transferStepType(String stepId) {
        // 截取到后两位
        String stepFrom = StrUtil.subWithLength(stepId, 0, stepId.length() - 2);
        // 截取后两位
        String stepEnd = StrUtil.subWithLength(stepId, stepId.length() - 2, stepId.length());
        BusinessStepTranslateEnum stepTranslateEnum = transfer(stepEnd);
        switch (stepTranslateEnum) {
            case OUTSIDE:
                stepFrom = stepFrom + INNER.code;
                break;
            case INNER:
                stepFrom = stepFrom + OUTSIDE.code;
                break;
            default:
                break;
        }
        return Long.valueOf(stepFrom);
    }

    public static BusinessStepTranslateEnum transfer(String code) {
        for (BusinessStepTranslateEnum value : BusinessStepTranslateEnum.values()) {
            if (ObjectUtil.equals(value.getCode(), code)) {
                return value;
            }
        }
        return null;
    }

}
